home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / PowerPlant / Everything / CModelessStuff.cp < prev    next >
Encoding:
Text File  |  1998-10-11  |  6.9 KB  |  314 lines  |  [TEXT/CWIE]

  1. // CModelessStuff.cp -- dialog methods
  2.  
  3. #include "CModelessStuff.h"
  4.  
  5. #include <UEnvironment.h>
  6. #include <UReanimator.h>
  7. #include <URegistrar.h>
  8. #include <LStream.h>
  9. #include <LTabGroup.h>
  10. #include <CustomControls.h>
  11. #include <LTextGroupBox.h>
  12. #include <LAMControlViewImp.h>
  13. #include <LGATextGroupBoxImp.h>
  14. #include <LPopupButton.h>
  15. #include <LAMPopupButtonImp.h>
  16. #include <LGAPopupButtonImp.h>
  17. #include <LScrollerView.h>
  18. #include <LScrollBar.h>
  19. #include <LAMTrackActionImp.h>
  20. #include <LStdScrollBarImp.h>
  21. #include <LTextTableView.h>
  22. #include <LCellSizeToFit.h>
  23. #include <LTextArray.h>
  24. #include <LTableArrayStorage.h>
  25. #include <UAttachments.h>
  26. #include <LTableMonoGeometry.h>
  27. #include <LTableSingleSelector.h>
  28. #include <CTextUtils.h>
  29.  
  30. #include "DModelessStuffData.h"
  31. #include "EverythingCmds.h"
  32. #include <PP_Messages.h>
  33.  
  34. const MessageT    msgTools    = 'Toos';
  35. const MessageT    msgFromValuesList2    = 'Fro2';
  36. const MessageT    msgFromMenu    = 'Frou';
  37. const MessageT    msgTextList    = 'Text';
  38.  
  39. #define PPob_ModelessStuffID    218
  40. #define RidL_ModelessStuffID    218
  41.  
  42. Boolean        CModelessStuff::sIsRegistered = false;
  43.  
  44. //----------
  45. CModelessStuff*        CModelessStuff::CreateModelessStuff (
  46.     LCommander*        inSuperCommander,
  47.     CommandT        inCommand,
  48.     DModelessStuffData*        inData)
  49. {
  50.     if (!sIsRegistered) {
  51.         RegisterClass ();
  52.     }
  53.     CModelessStuff*        dlog;
  54.     dlog = ((CModelessStuff *)LWindow::CreateWindow(PPob_ModelessStuffID, inSuperCommander));
  55.     dlog->mCommand = inCommand;
  56.     dlog->SetFromData (inData);
  57.  
  58.     return dlog;
  59. }
  60.  
  61. //----------
  62. #define    RegisterClasses(AbstractClass,AMImpClass,GAImpClass)    \
  63.     RegisterClass_(AbstractClass);    \
  64.     if (useAppearance) {    \
  65.         RegisterClassID_(AMImpClass, AbstractClass::imp_class_ID);    \
  66.     } else {    \
  67.         RegisterClassID_(GAImpClass, AbstractClass::imp_class_ID);    \
  68.     }
  69.  
  70. //----------
  71. void    CModelessStuff::RegisterClass ()
  72. {
  73.     Boolean        useAppearance = UEnvironment::HasFeature (env_HasAppearance);
  74.  
  75.     RegisterClass_(CModelessStuff);
  76.  
  77.     // register the pane classes we use
  78.     RegisterClasses (CControlPane, CustomControlImp, CustomControlImp);
  79.     RegisterClasses (LTextGroupBox, LAMControlViewImp, LGATextGroupBoxImp);
  80.     RegisterClasses (LPopupButton, LAMPopupButtonImp, LGAPopupButtonImp);
  81.     RegisterClass_(LScrollerView);
  82.     RegisterClasses (LScrollBar, LAMTrackActionImp, LStdScrollBarImp);
  83.     RegisterClass_(LTextTableView);
  84.  
  85.     sIsRegistered = true;
  86. }
  87.  
  88. //----------
  89. CModelessStuff::CModelessStuff (
  90.     LStream*    inStream)
  91.     : LGADialog (inStream)
  92. {
  93.     mData = nil;
  94. }
  95.  
  96. //----------
  97. CModelessStuff::~CModelessStuff()
  98. {
  99.     delete mData;
  100. }
  101.  
  102. //----------
  103. //    This member function gets called once the containment hierarchy that contains
  104. //    this pane has been built. It gives us a chance to get data members for
  105. //    interesting subviews, and to do other operations now that our subviews exist.
  106. void    CModelessStuff::FinishCreateSelf()
  107. {
  108.     LGADialog::FinishCreateSelf();
  109.  
  110.     mToolsPalette = (CControlPane*) FindPaneByID ('Toos');
  111.  
  112.     mFromValuesList2Popup = (LPopupButton*) FindPaneByID ('Fro2');
  113.  
  114.     mFromMenuPopup = (LPopupButton*) FindPaneByID ('Frou');
  115.  
  116.     mTextListTable = (LTextTableView*)FindPaneByID ('Text');
  117.     mTextListTable->AddListener(this);  // not a control so can't be included in RidL
  118.     mTextListTable->SetCellSizer (new LCellSizeToFit ());
  119.     mTextListTable->AddAttachment(new LEraseAttachment());
  120.     mTextListTable->SetTableGeometry(new LTableMonoGeometry(mTextListTable, 
  121.                             68 /* col width */, 
  122.                             11  /* row height */));
  123.     mTextListTable->SetTableSelector(new LTableSingleSelector(mTextListTable));
  124. // use LTextArray to contain list items
  125.     LTextArray* mTextListTableArray = new LTextArray;
  126.     *mTextListTableArray += "One";
  127.     *mTextListTableArray += "Two";
  128.     *mTextListTableArray += "Three";
  129.     *mTextListTableArray += "Infinity";
  130.     mTextListTable->SetTableStorage(new LTableArrayStorage(mTextListTable, mTextListTableArray));
  131.  
  132.  
  133.     UReanimator::LinkListenerToControls(this, this, RidL_ModelessStuffID);
  134.         // the purpose is to "connect" self to whatever controls
  135.         // that we want to "listen" to
  136.  
  137. // any additional initialization for your dialog:
  138.  
  139. }
  140.  
  141. //----------
  142. void    CModelessStuff::SetFromData (
  143.     DModelessStuffData*        inData)
  144. {
  145.     mData = inData;
  146.     mData->AddListener (this);
  147.  
  148.     mToolsPalette->SetValue (mData->GetTools3 ());
  149.     mFromValuesList2Popup->SetValue (mData->GetFromValuesList4 ());
  150.     mFromMenuPopup->SetValue (mData->GetFromMenu3 ());
  151.     mTextListTable->SetValue (mData->GetTextList3 ());
  152. }
  153.  
  154. //----------
  155. DModelessStuffData*        CModelessStuff::GetData ()
  156. {
  157.  
  158.     return mData;
  159. }
  160.  
  161. //----------
  162. void    CModelessStuff::DataChanged (
  163.     long        inDataID)
  164. {
  165.     StopListening ();
  166.  
  167.     if (inDataID == idTools3) {
  168.         mToolsPalette->SetValue (mData->GetTools3 ());
  169.     }
  170.     if (inDataID == idFromValuesList4) {
  171.         mFromValuesList2Popup->SetValue (mData->GetFromValuesList4 ());
  172.     }
  173.     if (inDataID == idFromMenu3) {
  174.         mFromMenuPopup->SetValue (mData->GetFromMenu3 ());
  175.     }
  176.     if (inDataID == idTextList3) {
  177.         mTextListTable->SetValue (mData->GetTextList3 ());
  178.     }
  179.  
  180.     StartListening ();
  181. }
  182.  
  183. //----------
  184. void    CModelessStuff::ListenToMessage (
  185.     MessageT    inMessage,
  186.     void        *ioParam)
  187. {
  188.     switch (inMessage) {
  189.     case msg_OK:
  190.             GetSuperCommander()->ProcessCommand(-mCommand, this);
  191.         break;
  192.  
  193.     case msg_Cancel:
  194.             DoClose();
  195.         break;
  196.  
  197.     case msgDataChanged:
  198.             DataChanged ((long)ioParam);
  199.         break;
  200.  
  201.     case msgTools:
  202.             mData->SetTools3 (mToolsPalette->GetValue ());
  203.         break;
  204.  
  205.     case msgFromValuesList2:
  206.             mData->SetFromValuesList4 (mFromValuesList2Popup->GetValue ());
  207.         break;
  208.  
  209.     case msgFromMenu:
  210.             mData->SetFromMenu3 (mFromMenuPopup->GetValue ());
  211.         break;
  212.  
  213.     case msgTextList:
  214.             mData->SetTextList3 (mTextListTable->GetValue ());
  215.         break;
  216.  
  217.  
  218.     default:
  219.           ; // do something
  220.         break;
  221.     }
  222. }
  223.  
  224. //----------
  225. Boolean        CModelessStuff::ObeyCommand (
  226.     CommandT    inCommand,
  227.     void*        ioParam)
  228. {
  229.     Boolean        cmdHandled = true;
  230.  
  231.     if (inCommand < 0) {
  232.         // modal dialog has finished
  233.  
  234.         switch (-inCommand) {
  235.         }
  236.  
  237.     } else {
  238.         switch (inCommand) {
  239.  
  240.         default:
  241.                 cmdHandled = LGADialog::ObeyCommand(inCommand, ioParam);
  242.             break;
  243.         }
  244.     }
  245.  
  246.     return cmdHandled;
  247. }
  248.  
  249. //----------
  250. void    CModelessStuff::FindCommandStatus (
  251.     CommandT    inCommand,
  252.     Boolean        &outEnabled,
  253.     Boolean        &outUsesMark,
  254.     Char16        &outMark,
  255.     Str255        outName)
  256. {
  257.     outUsesMark = false;
  258.  
  259.     switch (inCommand) {
  260.  
  261.     // +++ Add cases here for the commands you handle
  262.  
  263.     default:
  264.             LGADialog::FindCommandStatus(inCommand, outEnabled,
  265.                                             outUsesMark, outMark, outName);
  266.         break;
  267.     }
  268. }
  269.  
  270. // following functions will be obsoleted
  271. // retained only for backwards compatibility
  272. //----------
  273. Boolean
  274. CModelessStuff::GetToolsChoice()
  275. {
  276.     return mToolsPalette->GetValue();
  277. }
  278.  
  279. void
  280. CModelessStuff::SetToolsChoice (
  281.     Int32        inChoice)
  282. {
  283.     mToolsPalette->SetValue (inChoice);
  284. }
  285.  
  286. //----------
  287. short
  288. CModelessStuff::GetFromValuesList2PopupChoice ()
  289. {
  290.     return mFromValuesList2Popup->GetValue();
  291. }
  292.  
  293. void
  294. CModelessStuff::SetFromValuesList2PopupChoice (
  295.     short        choice)
  296. {
  297.     mFromValuesList2Popup->SetValue (choice);
  298. }
  299.  
  300. //----------
  301. short
  302. CModelessStuff::GetFromMenuPopupChoice ()
  303. {
  304.     return mFromMenuPopup->GetValue();
  305. }
  306.  
  307. void
  308. CModelessStuff::SetFromMenuPopupChoice (
  309.     short        choice)
  310. {
  311.     mFromMenuPopup->SetValue (choice);
  312. }
  313.  
  314.